package com.bamboo.framework.framework.security.controller;


import com.bamboo.framework.framework.security.entity.Role;
import com.bamboo.framework.framework.security.service.IRoleService;
import com.bamboo.framework.common.format.ReturnMsg;
import com.bamboo.framework.common.enums.Status;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 郭晴
 * @since 2018-12-15
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private IRoleService iRoleService;

    /**
     * 获取所有角色列表
     */
    @GetMapping("getAllPage")
    public ReturnMsg getAllRolePage(@RequestParam(defaultValue = "10") String size, @RequestParam(defaultValue = "1") String current) {
        Page<Role> page = new Page<>(Integer.valueOf(current).intValue(), Integer.valueOf(size).intValue());
        return new ReturnMsg(Status.SUCCESS, iRoleService.page(page));
    }

    /**
     * 保存角色
     */
    @PostMapping("saveRole")
    public ReturnMsg saveRole(@RequestParam(required = false) String id, @RequestParam String roleName) {
        return iRoleService.saveRole(id,roleName);
    }

    /**
     * 删除角色
     */
    @PostMapping("deleteRole")
    public ReturnMsg saveRole(@RequestParam String id) throws Exception {
        return iRoleService.deleteRoleById(id);
    }


    /**
     * 获取所有角色列表集合
     */
    @GetMapping("getAllList")
    public ReturnMsg getAllList() {
        return new ReturnMsg(Status.SUCCESS, iRoleService.list());
    }

    /**
     * 根据用户id获取当前用户拥有的角色id集合
     */
    @GetMapping("getRoleIdListByUserId")
    public ReturnMsg getRoleIdListByUserId(@RequestParam  Integer userId ) {
        return iRoleService.getRoleIdListByUserId(userId);
    }
}
